<!--
Date: 2025-08-13
Copyright (c) 2025 CAX Conversion Project
-->
<template>
  <el-dialog class="add_metal_library" v-model="props.addVisible" :title="modalType === 'edit' ? '修改' : '新增'" @close="handleVisible('cancel')">
    <el-form size="small" label-width="120px">
      <el-form-item label="属性代码">
        <el-input placeholder="请输入" v-model="formData.attributeCode" />
      </el-form-item>
      <el-form-item label="Exx">
        <el-input placeholder="请输入" v-model="formData.exx" />
      </el-form-item>
      <el-form-item label="Eyy">
        <el-input placeholder="请输入" v-model="formData.eyy" />
      </el-form-item>
      <el-form-item label="Gxy">
        <el-input placeholder="请输入" v-model="formData.gxy" />
      </el-form-item>
      <el-form-item label="厚度">
        <el-input placeholder="请输入" v-model="formData.thickness" />
      </el-form-item>
      <el-form-item label="对应PSHELL编号">
        <el-input placeholder="请输入" v-model="formData.pshellNumber" />
      </el-form-item>
      <el-form-item label="材料代码">
        <el-input placeholder="请输入" v-model="formData.materialCode" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button size="small" @click="handleVisible('cancel')">取消</el-button>
        <el-button size="small" type="primary" @click="submitAdd"> 确认 </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script name="addMetal" setup>
import { addMetal,updateMetal } from '@/api/layerLibrary';

const props = defineProps(['addVisible', 'rowData']);
const emit = defineEmits(['handleEvent']);
const modalType = props?.rowData ? 'edit' : 'add';
const formData = ref({
  attributeCode: '',
  exx: '',
  eyy: '',
  gxy: '',
  thickness: '',
  pshellNumber: '',
  materialCode: ''
});
if (modalType === 'edit') {
  formData.value = props.rowData;
}
const handleVisible = (type) => {
  if (type === 'cancel') {
    emit('handleEvent');
  } else {
    emit('handleEvent', { type: 'refresh' });
  }
};
const submitAdd = () => {
  if (modalType === 'add') {
    addMetal(formData.value).then((res) => {
      if (res) {
        ElMessage({ showClose: true, message: '新增成功。', type: 'success' });
        handleVisible();
      }
    });
  } else {
    updateMetal(formData.value).then((res) => {
      if (res) {
        ElMessage({ showClose: true, message: '修改成功。', type: 'success' });
        handleVisible();
      }
    });
  }
};
</script> 
<style lang="scss" scoped>
.add_metal_library {
  user-select: none;
}
</style>